import type { SearchBaseSelectors, SearchPageSelectors } from '../../../../module/page_enhancer/appearance/style_enhancement/platforms'

/**
 * 页面类型
 */
export enum BingPageType {
  Index = 'index',
  Web = 'web',
  Video = 'video',
  Academic = 'academic',
  Dictionary = 'dictionary',
  NotFound = 'not-found',
  Undefined = 'undefined',
  // 暂不支持
}

/**
 * 页面类型属性
 */
export interface BingPageTypeResult {
  type: BingPageType | 'default'
}

// ====================================================== 基础配置 ======================================================
// 搜索框容器
export const BING_SEARCH_BOX_SELECTOR: string = '#b_header #sb_form'
// 搜索结果项
export const BING_SEARCH_RESULT_CONTAINER_SELECTOR: string = '#b_content #b_results'
// 广告结果项
export const BING_SEARCH_AD_RESULT_CONTAINER_SELECTOR: string = ''

// 基础选择器
export const BING_SEARCH_BASE_SELECTORS: SearchBaseSelectors = {
  searchBox: {
    input: '#b_header #sb_form input#sb_form_q',
    form: '#b_header #sb_form',
    dropdown: {
      wrapper: '',
      menu: ``,
      hotRank: `${BING_SEARCH_BOX_SELECTOR} #sw_as #sa_pn_block`,
      suggestions: `${BING_SEARCH_BOX_SELECTOR} #sw_as #sa_sug_block`,
      history: `${BING_SEARCH_BOX_SELECTOR} #sw_as #sa_hs_block`,
      clearHistoryBtn: `${BING_SEARCH_BOX_SELECTOR} #sw_as #sa_hs_block .sa_rm a`,
      clearHistoryText: '删除',
    },
  },
  result: {
    container: BING_SEARCH_RESULT_CONTAINER_SELECTOR,
    item: `${BING_SEARCH_RESULT_CONTAINER_SELECTOR} > li:not(.b_pag, .b_msg)`,
  },
  adResult: {
    container: BING_SEARCH_AD_RESULT_CONTAINER_SELECTOR,
    item: BING_SEARCH_AD_RESULT_CONTAINER_SELECTOR,
    itemTitle: `${BING_SEARCH_AD_RESULT_CONTAINER_SELECTOR}`,
  },
  rightAside: {
    containerSelector: '#b_content aside',
    dragTargetSelector: `#b_context`,
    dragTargetStyle: `bottom: -18px; left: -32px;`,
    handleIconStyle: ``,
    position: 'left',
  },
}

// 页面选择器
export const BING_SEARCH_PAGE_SELECTORS: SearchPageSelectors = {
  [BingPageType.Web]: {
    ...BING_SEARCH_BASE_SELECTORS,
  },
  [BingPageType.Video]: {
    ...BING_SEARCH_BASE_SELECTORS,
    result: {
      container: `#b_content #vm_res #vsb_vid_cat :is(.ecc, .mc_fgvc)`,
      item: `#b_content #vm_res #vsb_vid_cat :is(.ecc > .mmlp, .mc_fgvc > .mc_fgvc_u)`,
    },
  },
  [BingPageType.Academic]: {
    ...BING_SEARCH_BASE_SELECTORS,
    result: {
      container: `#b_content #b_results`,
      item: `#b_content #b_results > li.aca_algo`,
    },
  },
  [BingPageType.Dictionary]: {
    ...BING_SEARCH_BASE_SELECTORS,
    result: {
      container: `.contentPadding #sentenceCon #sentenceSeg`,
      // 支持有结果和无结果的情况
      item: `.contentPadding #sentenceCon #sentenceSeg > :is(.se_li, div:has(> span))`,
    },
  },
  [BingPageType.Index]: {
    ...BING_SEARCH_BASE_SELECTORS,
    searchBox: {
      input: '#hp_app #sb_form input#sb_form_q',
      form: '#hp_app #sb_form',
      dropdown: {
        wrapper: '',
        menu: ``,
        hotRank: `#hp_app #sb_form #sw_as #sa_pn_block`,
        suggestions: `#hp_app #sb_form #sw_as #sa_sug_block`,
        history: `#hp_app #sb_form #sw_as #sa_hs_block`,
        clearHistoryBtn: `#hp_app #sb_form #sw_as #sa_hs_block .sa_rm a`,
        clearHistoryText: '删除',
      },
    },
  },
}
